<?
include 'includes/specs_functions.php';
echo printGoogleAnalytics();
#----------------------------------------------------
# Connect to PADS
$DB = getDB();
#-------------------------------$Session information
$SESSION = get_session($DB);
$CICUID = $SESSION->Character;
$THEME = $SESSION->Theme;
#---------------------------------------------------

$padCICUID = $_POST['padCICUID'];
//$padCICUID = 9545338;  // Nemi Chan

If($padCICUID == $CICUID){
	//MY OWN PAGE IF LOGGED IN
	$isOwn = true;
}else{
	$isOwn = false;
}


$output = " <script>				
			$(document).ready(function(){
				
				$('.show-spec').click(function(e) {	
					var clicked = jQuery(e.target);
					var id = clicked.attr('id');
					editSpec(id);
				});
				$('.pad-spec-row').click(function(e) {
					var tr = $(this).closest('tr');
					var specId = tr.attr('id');
					loadSpecDetail(specId);
					loadSpecComments(specId, 5);

				});
			});
		</script>
		<table id='me_specs' class='content-subtitle-table' style='width: 348px;margin-top: 4px;'>";
		
		$table = SPEC_TBL_SPECS." as spec";
		$col = array("spec.".SPEC_TBL_SPECS_ID." as specId"
			   ,"spec.".SPEC_TBL_SPECS_USER_ID." as userId"
			   ,"spec.".SPEC_TBL_SPECS_LAYOUT." as layout"
			   ,"spec.".SPEC_TBL_SPECS_JOB_ID." as jobId"
			   ,"spec.".SPEC_TBL_SPECS_LEVEL." as level"
			   ,"spec.".SPEC_TBL_SPECS_DESCRIPTION." as description"
			   ,"spec.".SPEC_TBL_SPECS_PUBLIC." as public"
			   ,"spec.".SPEC_TBL_SPECS_CDATE." as cdate"
			   ,"DATE_FORMAT(spec.".SPEC_TBL_SPECS_UDATE.",'%b %d %Y') as udate");
		$where = array("spec.".SPEC_TBL_SPECS_USER_ID." = \"".$padCICUID."\"");
		if(!$isOwn){
			array_push($where, "spec.".SPEC_TBL_SPECS_PUBLIC." = 'Y'");
		}
		$orderBy = "spec.".SPEC_TBL_SPECS_ID;
		$direction = "ASC";
		
		$result = $DB->GetData($table ,$col ,true ,$where, $orderBy, $direction);
		
		$max = 7;
		$num = $result[0];	
		$i = 1;
		$rest = $max - $num;

		foreach ($result[3] as $row) {
		
			$jobName = GetClass($row['jobId']);
		
			if($i==1){
				$output .= "<script>loadSpecDetail(".$row['specId']."); loadSpecComments(".$row['specId'].", 5); </script>";
			}
		
		
			$output .= "
				<tr id='".$row['specId']."' title='".$row['description']."' class='spec-row-hover pad-spec-row border-bottom cur-point' name='".$row['specId']."'>
					<td width='15%' align='center'><div class='normal-text bold-text'>".$row['level']."</div></td>
					<td width='15%' align='left'><img src='".GetClassIcon($jobName)."' style='width:31px;'/></td>
					<td width='30%' align='left'><div class='normal-text bold-text'>".$jobName."</div></td>
					<td width='40%' align='right'><div class='normal-text bold-text' style='font-size:9px;padding-right: 20px;'>".$row['udate']."</div></td>
				</tr>";
				
			//<img class='cur-point' src='".$TODO."' />
			if($i == $max){
				break;
			}	
			
			$i++;
			
		}
		if ($rest > 0){
		
			for ($i = 1; $i <= $rest; $i++) {
				
				if($isOwn){
					$output .= "<tr id='' title='Create a spec' class='pad-spec-row cur-point ";
				}else{
					$output .= "<tr id='' class='tr-table ";
				}
				if(!($num == 0 && $i == 1))	{
					$output .= "border-top";
				}
				$output .= " spec-row-hover'>
						<td width='15%' align='center'><div class='normal-text bold-text'></div></td>
						<td width='15%' align='left'><img src='specs/media/no-av.png' style='width:31px;height:31px;'/></td>
						<td width='70%' align='left' colspan='2'><div class='normal-text bold-text'>Empty slot</div></td>
					</tr>";
					
			}
		}

	
$output .= "	</table>";

echo  $output;

#------------------------------------------------------------------------
# Disconnect
leaveDB($DB);


?>